<template>
  <div class="container">
    <van-nav-bar
      title="来料检验录入"
      fixed
      class="titleStyle"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-button
      class="saveBtn"
      type="primary"
      native-type="submit"
      @click="submitForm"
      >提交</van-button
    >
    <div class="publicBox">
      <div class="checkInputTop">
        <div class="checkInputTopCont">
          <h1>
            <span>到货单号：{{ detailsObj.invoiceNo }}</span>
          </h1>
          <ul>
            <li>
              <div>
                <b>品名</b>
                <em>
                  <van-field
                    v-model="detailsObj.materialName"
                    readonly
                    size="mini"
                  />
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>料号</b>
                <em>
                  <van-field
                    v-model="detailsObj.materialCode"
                    readonly
                    size="mini"
                  />
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>规格</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="detailsObj.specifications"
                      readonly
                      size="mini"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>送检日期</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="detailsObj.carryCheckAt"
                      readonly
                      size="mini"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>送检数量</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="detailsObj.incomingNum"
                      readonly
                      size="mini"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>批号</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="detailsObj.planBatchNo"
                      readonly
                      size="mini"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>供方检验员</b>
                <em>
                  <van-field
                    v-model="ruleForm.supplierCheckName"
                    size="mini"
                    @click="showUser = true"
                  />
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>抽样数</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="ruleForm.checkNum"
                      :formatter="formatter"
                      type="number"
                      placeholder="请输入数字"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>入库数量</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="ruleForm.inWarehouseNum"
                      :formatter="formatter"
                      type="number"
                      placeholder="请输入数字"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="checkContent">
        <el-table
          :style="{
            borderColor: '#ccc',
            'border-right': '1px solid #ccc',
            'border-bottom': '1px solid #ccc',
          }"
          :data="tableData"
          border
          height="100%"
          :cell-style="{ borderColor: '#ccc' + ' !important' }"
          :header-cell-style="{
            background: '#fff !important',
            borderColor: '#ccc' + ' !important',
          }"
        >
          <el-table-column
            type="index"
            label="序号"
            width="50px"
            align="center"
          />
          <el-table-column
            align="center"
            prop="itemName"
            label="检验项目"
            min-width="100px"
            show-overflow-tooltip
          />
          <el-table-column
            align="center"
            prop="difference"
            label="标准值"
            min-width="100px"
            show-overflow-tooltip
          />
          <el-table-column
            align="center"
            prop="upperDifference"
            label="上差"
            min-width="100px"
            show-overflow-tooltip
          />
          <el-table-column
            align="center"
            prop="lowerDifference"
            label="下差"
            min-width="100px"
            show-overflow-tooltip
          />
          <el-table-column label="实测结果" align="center">
            <el-table-column
              v-for="(itx, index) in tableData.length > 0
                ? tableData[0].mttrs
                : ''"
              :key="index"
              width="120"
            >
              <template slot="header">{{ itx.name }}</template>
              <template #default="{ row }">
                <!-- 自动 -->
                <van-field
                  v-if="row.inspectionMethod == 2"
                  v-model="row.mttrs[index].value"
                  :formatter="formatter"
                  type="number"
                  placeholder="请输入数字"
                  @blur="inputBlur($event, row, row.mttrs[index])"
                  :style="{
                    background: row.mttrs[index].isQualified ? '' : 'red',
                  }"
                />
                <!-- 手动 -->
                <van-field
                  v-else
                  v-model="row.mttrs[index].value"
                  size="mini"
                  readonly
                  @click="showHandClick(row, row.mttrs[index])"
                />
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column
            align="center"
            prop="actualValue"
            label="实测范围"
            width="100px"
            show-overflow-tooltip
          >
            <template #default="{ row }">{{ row.actualValue }}</template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="decide"
            label="判定"
            width="100px"
          >
            <template #default="{ row }">
              <div
                v-if="!row.mttrs.every((item) => item.isQualified)"
                class="decideClass1"
              >
                NG
              </div>
              <div v-else class="decideClass2">OK</div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="checkInputTop">
        <div class="checkInputTopCont checkInputBottomCont">
          <h1>
            <span>结论：{{ detailsObj.checkResult }}</span>
          </h1>
          <ul>
            <li>
              <div>
                <b>检验员</b>
                <em>
                  <van-field
                    v-model="ruleForm.checkName"
                    size="mini"
                    @click="showUser2 = true"
                  />
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>检验日期</b>
                <em>
                  <van-field
                    v-model="ruleForm.checkAt"
                    @click="showTime1 = true"
                    size="mini"
                  />
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>审核</b>
                <em>
                  <van-cell-group>
                    <!-- approvedName -->
                    <!-- checkUserName -->
                    <van-field
                      v-model="ruleForm.approvedName"
                      size="mini"
                      readonly
                      @click="showUser1 = true"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
            <li>
              <div>
                <b>审核日期</b>
                <em>
                  <van-cell-group>
                    <van-field
                      v-model="ruleForm.approvedAt"
                      @click="showTime2 = true"
                      size="mini"
                    />
                  </van-cell-group>
                </em>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!--  时间选择 -->
    <van-popup v-model="showTime" position="bottom" :style="{ height: '30%' }">
      <van-datetime-picker
        v-model="currentDate"
        type="datetime"
        @confirm="onTimeChange"
        @cancel="showTime = false"
      />
    </van-popup>
    <!-- 人员选择 -->
    <van-popup v-model="showUser" position="bottom">
      <van-picker
        title="人员选择"
        show-toolbar
        :columns="userList"
        @confirm="onConfirm"
        @cancel="showUser = false"
      />
    </van-popup>
    <!-- 审核人员选择 -->
    <van-popup v-model="showUser1" position="bottom">
      <van-picker
        title="人员选择"
        show-toolbar
        :columns="userList"
        @confirm="onConfirm1"
        @cancel="showUser1 = false"
      />
    </van-popup>
    <!-- 审核人员选择 -->
    <van-popup v-model="showUser2" position="bottom">
      <van-picker
        title="人员选择"
        show-toolbar
        :columns="userList"
        @confirm="onConfirm2"
        @cancel="showUser2 = false"
      />
    </van-popup>
    <!-- 手动选择 -->
    <van-popup v-model="showHand" position="bottom">
      <van-picker
        title="手动选择"
        show-toolbar
        :columns="columnsHand"
        @confirm="onConfirmHand"
        @cancel="showHand = false"
      />
    </van-popup>
    <!-- 检验日期选择 -->
    <van-popup v-model="showTime1" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        :min-date="minDate"
        @confirm="timej"
      />
    </van-popup>
    <!-- 审核日期选择 -->
    <van-popup v-model="showTime2" position="bottom">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        :min-date="minDate"
        @confirm="timeS"
      />
    </van-popup>
  </div>
</template>
<script>
import { myFunction } from "../../../../utils/function";
export default {
  name: "FirstInspection",
  data() {
    return {
      cloneValue: {},
      cloneIndex: {},
      showHand: false,
      currentDate: new Date(),
      columnsHand: ["OK", "NG"],
      showTime1: false,
      showTime2: false,
      showUser1: false,
      showUser2: false,
      userList: [],
      itemList: [],
      ruleForm: {
        itemList: [],
        result: 1,
        checkName: "",
        approvedName: "",
        qualifiedNum: null,
        unqualifiedNum: null,
        badNum: null,
        checkUserName: JSON.parse(localStorage.getItem("padUserInfo")).data
          .userName, // 检验人
        checkTime: myFunction(new Date()), // 检验时间
        checkUserId: JSON.parse(localStorage.getItem("padUserInfo")).data
          .userId, // 本次检验
      },
      show: false,
      code: localStorage.getItem("code"),
      search: {
        current: 1,
        size: 5,
      },
      list: [],
      loading: false,
      isLoading: false,
      detailsObj: {},
      disabledResult: false,
      showTime: false,
      showUser: false,
      disabledYorNo: true,
      tableData: [
        // {
        //   id: 1,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: 1000,
        //   lowerDifference: 100,
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 2,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 3,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 4,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 5,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 6,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 7,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 8,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 9,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 10,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 11,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // },
        // {
        //   id: 12,
        //   itemName: '',
        //   difference: '',
        //   upperDifference: '',
        //   lowerDifference: '',
        //   mttrs: [
        //     {
        //       xuhao: '1#',
        //       value: '7'
        //     },
        //     {
        //       xuhao: '2#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '3#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '4#',
        //       value: ''
        //     },
        //     {
        //       xuhao: '5#',
        //       value: ''
        //     }
        //   ]
        // }
      ],
      minDate: new Date(2025, 0, 1),
    };
  },
  watch: {
    ruleForm: {
      deep: true,
      handler(row) {
        row.reportNum = this.detailsObj.reportNum;
        // row.checkNum = this.detailsObj.reportNum;
        row.qualifiedNum =
          Number(this.detailsObj.reportNum) -
          Number(row.unqualifiedNum) -
          Number(row.badNum);
        // if (Number(row.unqualifiedNum) + Number(row.badNum) > row.checkNum) {
        //   this.$toast.fail("不合格数+废品数>检验数量，请核实！");
        //   row.unqualifiedNum = 0;
        //   row.badNum = 0;
        // }
        if (Number(row.unqualifiedNum) > 0 || Number(row.badNum) > 0) {
          this.disabledYorNo = false;
        } else {
          this.disabledYorNo = true;
        }
      },
    },
  },
  created() {
    // this.search.proBatchNo = this.$route.query.code
  },
  mounted() {
    this.getData();
  },
  methods: {
    async getData(row) {
      // const toast = this.$toast.loading({
      //   duration: 0, // 持续展示 toast
      //   message: '数据加载中...',
      //   forbidClick: true,
      //   loadingType: 'spinner'
      // })
      this.detailsObj = this.$store.state.data;
      this.detailsObj.checkResult = "不合格";
      const res = await this.$axios.post(
        `/dobo-product/pro/incoming/check/enterDetails?id=${this.$store.state.data.id}`
      );
      if (res.data.code === 200) {
        this.tableData = res.data.data.map((i) => {
          return {
            ...i,
            actualValue: "",
            decide: "NG",
            mttrs: [
              {
                name: "1#",
                value: "",
                isQualified: false,
              },
              {
                name: "2#",
                value: "",
                isQualified: false,
              },
              {
                name: "3#",
                value: "",
                isQualified: false,
              },
              {
                name: "4#",
                value: "",
                isQualified: false,
              },
              {
                name: "5#",
                value: "",
                isQualified: false,
              },
            ],
          };
        });
        // this.userLists = res.data.data
        // res.data.data.forEach((item) => {
        //   this.userList.push(item.name)
        // })
      }
      /* 获取人员 */
      await this.getUser();
      // await this.getItemList(toast)
    },
    /* 获取所有人员 */
    async getUser() {
      const res = await this.$axios.get("/dobo-user/user/getAllUser");
      if (res.data.code === 200) {
        this.userLists = res.data.data;
        res.data.data.forEach((item) => {
          this.userList.push(item.name);
        });
      }
    },
    /* 获取质量控点 */
    async getItemList(toast) {
      const res = await this.$axios.get(
        `/dobo-product/pad/head/getItemList?bomId=${this.detailsObj.bomId}&materialId=${this.detailsObj.materialId}&procedureCode=${this.detailsObj.procedureCode}&routeId=${this.detailsObj.routeId}`
      );
      if (res.data.code === 200) {
        if (res.data.data.length < 1) {
          setTimeout(() => {
            toast.clear();
          }, 100);
          this.$dialog
            .alert({
              title: "提示",
              message: "当前数据没有质量控点请维护质量控点！",
            })
            .then(() => {
              this.$router.go(-1);
            });
          return;
        } else {
          setTimeout(() => {
            toast.clear();
            res.data.data.forEach((item) => {
              item.result = null;
              item.tool = [];
              item.unqualifiedNum = 0;
              if (item.toolId) {
                item.itemToolEntityList = [];
                this.itooles.forEach((itx) => {
                  if (itx.toolId === item.toolId) {
                    item.tool.push(itx.toolId);
                    item.itemToolEntityList.push(itx);
                    delete itx.id;
                  }
                });
              }
            });
            this.ruleForm.itemList = res.data.data;
          }, 10);
        }
      }
    },
    timej(e) {
      this.showTime1 = false;
      this.ruleForm.checkAt = myFunction(e);
    },
    timeS(e) {
      this.showTime2 = false;
      this.ruleForm.approvedAt = myFunction(e);
    },
    /* 选择时间 */
    selectTime() {
      this.showTime = true;
    },
    /* 时间选择赋值 */
    onTimeChange(value) {
      this.ruleForm.checkTime = myFunction(value);
      this.showTime = false;
    },
    /* 手动选择 */
    onConfirmHand(e) {
      if (e == "OK") {
        this.tableData.forEach((i) => {
          if (i.checkItemId == this.cloneValue.checkItemId) {
            i.mttrs.forEach((x) => {
              if (x.name == this.cloneIndex.name) {
                x.isQualified = true;
              }
            });
          }
        });
      } else {
        this.tableData.forEach((i) => {
          if (i.checkItemId == this.cloneValue.checkItemId) {
            i.mttrs.forEach((x) => {
              if (x.name == this.cloneIndex.name) {
                x.isQualified = false;
              }
            });
          }
        });
      }
      this.tableData.forEach((i) => {
        if (i.checkItemId == this.cloneValue.checkItemId) {
          i.mttrs.forEach((x) => {
            if (x.name == this.cloneIndex.name) {
              x.value = e;
            }
          });
        }
      });
      this.tableData.forEach((i) => {
        if (i.checkItemId == this.cloneValue.checkItemId) {
          i.decide = i.mttrs.every((item) => item.isQualified) ? "OK" : "NG";
        }
      });
      this.detailsObj.checkResult = this.tableData.every(
        (item) => item.decide == "OK"
      )
        ? "合格"
        : "不合格";
      this.showHand = false;
    },
    showHandClick(val, index) {
      this.showHand = true;
      this.cloneValue = val;
      this.cloneIndex = index;
    },
    onConfirm(e) {
      let id = "";
      this.userLists.forEach((item) => {
        if (item.name === e) id = item.id;
      });
      this.ruleForm.checkUserId = id;
      this.ruleForm.checkUserName = e;
      this.ruleForm.supplierCheckBy = id;
      this.ruleForm.supplierCheckName = e;
      this.showUser = false;
    },
    onConfirm1(e) {
      let id = "";
      this.userLists.forEach((item) => {
        if (item.name === e) id = item.id;
      });

      this.ruleForm.approvedName = e;
      this.ruleForm.approvedBy = id;
      this.showUser1 = false;
    },
    onConfirm2(e) {
      let id = "";
      this.userLists.forEach((item) => {
        if (item.name === e) id = item.id;
      });

      this.ruleForm.checkBy = id;
      this.ruleForm.checkName = e;
      this.showUser2 = false;
    },
    /** 验证检验数量只可输入大于等于0 的整数 */
    formatter(value) {
      return value.replace(/^(\-)*(\d+)\.(\d{2}).*$/, "$1$2.$3");
    },
    sum(arr) {
      return arr.reduce(function (prev, curr, idx, arr) {
        return prev + curr;
      });
    },
    submitForm() {
      if (this.ruleForm.checkName == "" || this.ruleForm.approvedName == "") {
        this.$dialog.alert({
          type: "danger",
          title: "失败提示",
          message: "审核员和检验员为必填！",
        });
      } else {
        this.$dialog
          .confirm({
            title: "提示",
            message: "是否确认提交？",
          })
          .then(() => {
            // 当质量控点中所有次品数之和≠不合格数+废品数时
            // const num =
            //   Number(this.ruleForm.unqualifiedNum) + Number(this.ruleForm.badNum);
            // const arr = this.ruleForm.itemList.map(
            //   (item) => +item.unqualifiedNum
            // );
            // if (this.sum(arr) === num) {
            //   this.ruleForm.itemList.forEach((item) => {
            //     if (item.itemFileEntityList) {
            //       item.itemFileEntityList.forEach((itx) => delete itx.content);
            //     }
            //     delete item.toolId;
            //     delete item.tool;
            //     if (item.unqualifiedNum === "") {
            //       item.unqualifiedNum = 0;
            //     }
            //   });
            //   this.submitApi();
            // } else {
            //   this.$toast.fail(
            //     "质量控点中所有次品数之和≠不合格数+废品数，请核实！"
            //   );
            // }
            const detatilVo = this.tableData.map((i) => {
              return {
                ...i,
                measuredResultsFirst: i.mttrs[0].value,
                measuredResultsSecond: i.mttrs[1].value,
                measuredResultsThird: i.mttrs[2].value,
                measuredResultsFourth: i.mttrs[3].value,
                measuredResultsFifth: i.mttrs[4].value,
              };
            });

            const obj = {
              ...this.detailsObj,
              ...this.ruleForm,
              checkResult: this.detailsObj.checkResult == "合格" ? 1 : 0,
              detatilVo: detatilVo,
              checkAt: this.ruleForm.checkAt,
              checkBy: this.ruleForm.checkBy,
              checkName: this.ruleForm.checkName,
              approvedAt: this.ruleForm.approvedAt,
              status: 2,
            };
            console.log(obj);
            this.$axios
              .post("/dobo-product/pro/incoming/check/enterDetailsSave", obj)
              .then((res) => {
                if (res.data.code == 200) {
                  // toast.clear();
                  this.$dialog
                    .alert({
                      title: "提示",
                      message: "提交成功!",
                    })
                    .then(() => {
                      this.$router.push("/incomingInspection");
                    })
                    .catch(() => {});
                } else {
                  this.$toast.fail(res.data.msg);
                  setTimeout(() => {
                    toast.clear();
                    this.$router.push("/incomingInspection");
                  }, 1000);
                }
              })
              .catch(() => {});
          })
          .catch(() => {
            return false;
          });
      }
    },
    submitApi() {
      const toast = this.$toast.loading({
        duration: 0, // 持续展示 toast
        message: "提交中...",
        forbidClick: true,
        loadingType: "spinner",
      });
      this.ruleForm.reportId = this.detailsObj.id;
      this.$axios
        .post("/dobo-product/pad/head/save", this.ruleForm)
        .then((res) => {
          if (res.data.code === 200) {
            toast.clear();
            this.$dialog
              .alert({
                title: "提示",
                message: "提交成功!",
              })
              .then(() => {
                this.$router.push("/incomingInspection");
              })
              .catch(() => {});
          } else {
            this.$toast.fail(res.data.msg);
            setTimeout(() => {
              toast.clear();
              this.$router.push("/incomingInspection");
            }, 1000);
          }
        })
        .catch(() => {});
    },

    // 输入框数据识别
    inputBlur(e, row, index) {
      if (
        e.target.value >= row.difference - row.lowerDifference &&
        e.target.value <= Number(row.difference) + Number(row.upperDifference)
      ) {
        index.isQualified = true;
      } else {
        index.isQualified = false;
      }
      row.actualValue = this.getRangeByField(row.mttrs, "value");
      this.tableData.forEach((i) => {
        if (i.checkItemId == row.checkItemId) {
          i.decide = i.mttrs.every((item) => item.isQualified) ? "OK" : "NG";
        }
      });
      this.detailsObj.checkResult = this.tableData.every(
        (item) => item.decide == "OK"
      )
        ? "合格"
        : "不合格";
    },
    getRangeByField(array, field) {
      if (array.length === 0) return 0; // 如果数组为空，返回 0

      const { max, min } = array.reduce(
        (acc, item) => ({
          max: Math.max(acc.max, item[field]),
          min: Math.min(acc.min, item[field]),
        }),
        { max: -Infinity, min: Infinity } // 初始值
      );

      return `${min}~${max}`;
    },
    // 返回
    onClickLeft() {
      const { query } = this.$route;
      if (query.path) {
        this.$router.push(`/${query.path}`);
      } else {
        this.$router.push("/incomingInspection");
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  .checkInputTopCont {
    padding: 5px;
    h1 {
      height: 35px;
      line-height: 35px;
      font-weight: normal;
      text-align: center;
      background: #eeee;
    }
    ul {
      li {
        width: 33.3333%;
        height: auto;
        b {
          width: 100%;
          text-align: left;
          height: 35px;
          line-height: 35px;
          font-size: 20px;
        }
        em {
          width: 100%;
          .van-cell {
            width: 98%;
          }
        }
      }
      // li:first-child {
      //   width: 100% !important;
      //   .van-cell {
      //     width: 98% !important;
      //   }
      // }
    }
  }
  .checkContent {
    border-left: 1px solid #ccc;
    height: 34%;
    // overflow: hidden;
  }
  .checkInputBottomCont {
    ul {
      li {
        width: 50%;
      }
    }
  }
}
</style>
<style lang="scss">
.checkContent {
  .el-table .el-table__cell {
    padding: 5px 0;
    .van-cell {
      padding: 5px;
      border: 1px solid #ccc;
    }
  }
}
.decideClass1 {
  width: 100%;
  height: 100%;
  background: red;
}
.decideClass2 {
  width: 100%;
  height: 100%;
  background: green;
}
</style>
